﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XModel;

namespace XDAL
{
    public class tbImageItem : tbBase<tbImageItem>
    {
        private const int mLimitShowCount = 20;
        private const string SQL_INSERT = "INSERT INTO tbImageItem (sTitle,nCount,nViewScore,sPath,date) VALUES(@sTitle,@nCount,@nViewScore,@sPath,now());SELECT @@IDENTITY";
        private static string SQL_SELECT = "SELECT * FROM tbImageItem WHERE (date< now()) order by ID ASC LIMIT @index," + mLimitShowCount + "";



        public List<EImageItem> Get(int count)
        {
            MySql.Data.MySqlClient.MySqlParameter[] parms = new MySql.Data.MySqlClient.MySqlParameter[]{
                new MySql.Data.MySqlClient.MySqlParameter("@index",count)
            };
            List<EImageItem> ret = MySQL.MySqlHelper.ReadToEntity<EImageItem>(MySQL.MySqlHelper.ExecuteReader(SQL_SELECT, parms));
            return ret;
        }

        public bool Insert(EImageItem item)
        {
            MySql.Data.MySqlClient.MySqlParameter[] parms = new MySql.Data.MySqlClient.MySqlParameter[]{
                new MySql.Data.MySqlClient.MySqlParameter("@"+EImageItem.KET_TITLE,item.sTitle),
                new MySql.Data.MySqlClient.MySqlParameter("@"+EImageItem.KET_PATH,item.sPath),
                new MySql.Data.MySqlClient.MySqlParameter("@"+EImageItem.KET_COUNT,item.nCount),
                new MySql.Data.MySqlClient.MySqlParameter("@"+EImageItem.KET_SCORE,item.nViewScore),
            };
            return MySQL.MySqlHelper.ExecuteNonQuery(SQL_INSERT, parms) > 0;
        }
    }
}
